import { requestClient } from '#/api/request';
import type { PaginationParams } from '../type';
import type { CourseInfoApiResponse } from '../../views/course/modules/course-mgr/types';


// 课程详情参数类型
export interface CourseDetailParams {
  id?: number;
  name: string;           // 课程名称
  instructors?: string;    // 授课老师
  producer?: string;       // 出品方
  summary?: string;        // 课程概述
  icon?: string;           // 课程图标
}

export interface CourseInfoParams extends PaginationParams {
  name?: string | null
  status?: string | null
  idList?: string[] | null
}

export interface CourseInfoByCertIdParams {
  certificateId?: string;
  courseId?: string;
}

export async function getCourseInfoApi(params: CourseInfoParams): Promise<CourseInfoApiResponse> {
  return requestClient.get('/course/get-course-info', { params });
}

/**
 * 根据认证Id查询课程信息
 * @param certificateId 认证ID
 * @param courseId 课程ID
 * @returns Promise<any>
 */
export async function getCourseInfoByCertIdApi(params: CourseInfoByCertIdParams): Promise<any> {
  return requestClient.get('/course/open/get-course-info-by-cert-id', { params });
}

export async function createCourseInfoApi(data: CourseDetailParams): Promise<any> {
  return requestClient.post('/course/create-course-info', data);
}

export async function updateCourseInfoApi(data: CourseDetailParams): Promise<any> {
  return requestClient.patch('/course/update-course-info', data);
}
// 保存基本信息草稿
export async function saveDraftCourseInfoApi(data: CourseDetailParams): Promise<any> {
  return requestClient.patch('/course/save-draft-course-info', data);
}

/**
 * 删除课程信息
 * @param id 课程ID
 * @returns Promise<any>
 */
export async function deleteCourseInfoApi(id: number): Promise<any> {
  return requestClient.delete(`/course/delete-course-info/${id}`);
}

/**
 * 上架课程
 * @param id 课程ID
 * @returns Promise<any>
 */
export async function listedCourseInfoApi(id: number): Promise<any> {
  return requestClient.patch(`/course/listed-course-info/${id}`);
}

/**
 * 下架课程
 * @param id 课程ID
 * @returns Promise<any>
 */
export async function unlistedCourseInfoApi(id: number): Promise<any> {
  return requestClient.patch(`/course/unlisted-course-info/${id}`);
}

/**
 * 查询草稿状态的课程详情
 * @param courseId 课程ID
 * @returns Promise<any>
 */
export async function getCourseDetailApi(courseId: number | string): Promise<any> {
  return requestClient.get(`/course/get-course-detail/${courseId}`);
}

/**
 * 创建课程目录
 * @param data 课程目录数据
 * @returns Promise<any>
 */
export async function createCourseDirectoryApi(data: any): Promise<any> {
  return requestClient.post('/course/manage-course-directory', data);
}

/**
 * 保存课程目录草稿
 * @param data 课程目录数据
 * @returns Promise<any>
 */
export async function saveDraftCourseDirectoryApi(data: any): Promise<any> {
  return requestClient.patch('/course/save-draft-course-directory', data);
}

/**
 * 查询课程目录
 * @param courseId 课程ID
 * @returns Promise<any>
 */
export async function getCourseDirectoryApi(courseId: number | string): Promise<any> {
  return requestClient.get(`/course/get-course-directory`, { params: { courseId, needContent: true } });
}

/**
 * 课程点击埋点
 * @param courseId 课程ID
 * @returns Promise<any>
 */
export async function courseClickTrackingApi(courseId: number | string): Promise<any> {
  return requestClient.post(`/course/open/click/${courseId}`);
}
